@using Khaaaantest
@using Umbraco.Web
@using umbraco.BusinessLogic
@using umbraco.MacroEngines
@using umbraco.cms.businesslogic.web
@inherits umbraco.MacroEngines.DynamicNodeContext

<div class="contests">
    <h1>@Model.title</h1>
    <p>Here is the list of your contests.</p>
    @foreach(var contest in CurrentModel.GetChildrenAsList.Items)
    {
        
        var dynContest = (dynamic) contest;

        // var imageSrc = Utilities.GetMediaSrcOrEmptyString(Model.image);
        var imageSrc = "/media/Khaaaantest/defacto.png";
        var title = @dynContest.title;
        
        var dotdotdot = "";
        // UmbracoHelper.StripHtml(dynContest.text, null)
        var snippet = Utilities.GetFirstFewWords(dynContest.text + "", 140);
        if (snippet.Length > 140)
        {
            dotdotdot = "...";
        }
        
        <div class="contests_contest">
            @if (imageSrc != "")
            {
                <a href="@contest.NiceUrl"><img src="@imageSrc" alt="@title" /></a>
            }
            <div>
                <h3><a href="@contest.NiceUrl">@title</a></h3>
                <p>@snippet@dotdotdot</p>
            </div><br clear="all"/>
        </div>
            
    }
</div>

@{
    // This is only to uninstall the package, switch the value to true and run the script.
    const bool deleteDocumentTypes = false;
    if (deleteDocumentTypes)
    {
        // Before deleting, create a dump backup of the content nodes.
        // todo: Before deleting, create a dump backup of the content nodes.

        // Starting point "_Khaaaantest_Master"
        var root = DocumentType.GetByAlias("_Khaaaantest_Master");

        // Get a list of it's descendant document type ids
        var descendantIds = Utilities.RecursivelyGetDescendantIds(root);

        // Now delete leaf doc types until there are none left
        Utilities.RecursivelyDeleteKhaaaantestContestDocumentTypes(descendantIds);
        
        <div class="box" style="background-color: palegreen;">
            Successfully deleted all the document types under "_Khaaaantest_Master".
        </div>
    }
}